package com.scenci.show.controller;

import com.scenci.show.bean.DataShow;
import com.scenci.show.service.ShowService;
import com.scenci.show.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 *  @author: James
 *  @Date: 2020/5/9 11:02
 *  @Description:
 */

@RestController
@RequestMapping("/bigdata")
public class ShowController {
    @Autowired
    ShowService showService;
    @GetMapping("/show")
    public Object queryPoint(){
        List<DataShow> dataShow = showService.queryPoint();
        return ResponseUtil.okList(dataShow);
    }
    @GetMapping("/show1")
    public Object queryPoint1(){
        LinkedHashMap<String, Object> map = new LinkedHashMap<>();
        String name = "";
        String arr1[] = {};
        List<DataShow> dataShow = showService.queryPoint();
        for (DataShow a : dataShow){
            double arr[] = new double[2];
            name = a.getSightName();
            arr1 = a.getPoint().split(",");
            for(int i=0;i<arr1.length;i++){
                arr[i] = Double.parseDouble(arr1[i]);
            }
            map.put(name,arr);
        }
        return ResponseUtil.ok(map);
    }
    @GetMapping("/show2")
    public Object queryPoint2(){
        List<DataShow> dataShow = showService.queryPoint();
        ArrayList<Map> array=new ArrayList<Map>();
        String name = "";
        int value =0;
        for (DataShow a : dataShow){
            Map<String, Object> map = new HashMap<>();
            name = a.getSightName();
            value = Integer.parseInt(a.getSaleCount());
            map.put("name",name);
            map.put("value",value);
            array.add(map);
        }
        return ResponseUtil.okList(array);
    }

}
